//
//  CategoryView.m
//  MindBox
//
//  Created by MS on 16-1-5.
//  Copyright (c) 2016年 Lemon. All rights reserved.
//

#import "CategoryView.h"
#import "UIView+Frame.h"
#import "Category_NameBaseView.h"
#import "Category_GoodsView.h"
@interface CategoryView ()<Category_NameBaseViewDelegate,Category_GoodsViewDelegate>
@property (nonatomic,weak)  Category_NameBaseView * category_NameBaseView;
@property (nonatomic,weak)  Category_GoodsView * category_GoodsView;
@end

@implementation CategoryView

-(void)setCategory_names:(NSArray *)category_names
{
    _category_names = category_names;
    self.category_NameBaseView.category_names = category_names;
}

-(void)setCategory_goods:(NSArray *)category_goods
{
    _category_goods = category_goods;
    
    self.category_GoodsView.category_goods = category_goods;
    [self.category_GoodsView.collectionView reloadData];
}

-(Category_NameBaseView *)category_NameBaseView
{
    if (_category_NameBaseView==nil) {
        Category_NameBaseView * view = [[Category_NameBaseView alloc] init ];
        _category_NameBaseView = view;
        _category_NameBaseView.delegate_name = self;
        [self addSubview:view];
    }
    return _category_NameBaseView;
}

-(Category_GoodsView *)category_GoodsView
{
    if (_category_GoodsView==nil) {
        Category_GoodsView * view = [[Category_GoodsView alloc] init];
        _category_GoodsView = view;
        _category_GoodsView.delegate = self;
        [self addSubview:view];
    }
    return _category_GoodsView;
}

#pragma mark Category_NameBaseView代理方法
-(void)category_NameBaseViewDidClick:(Category_NameBaseView *)nameView categoryName:(Category_Name *)categoryName index:(NSInteger)index
{
    if ([self.delegate respondsToSelector:@selector(categoryNameViewDidClick:categoryName:index:)]) {
        [self.delegate categoryNameViewDidClick:self categoryName:categoryName index:index];
        self.category_GoodsView.category_case = categoryName.banner;
    }
    
}

#pragma mark  Category_GoodsView代理方法
-(void)category_GoodsViewDidClick:(Category_GoodsView *)goodsView categoryGoods:(Son_Category *)goods categoryCase:(Category_Case *)category_case index:(NSInteger)index
{
    if ([self.delegate respondsToSelector:@selector(categoryGoodsViewDidClick:categoryGoods:categoryCase:index:)]) {
        [self.delegate categoryGoodsViewDidClick:self categoryGoods:goods categoryCase:category_case index:index];
    }
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.category_NameBaseView.frame = CGRectMake(0, 0, self.width/4, self.height-64);
    self.category_GoodsView.frame =CGRectMake(self.width/4, 0, self.width*3/4, self.height);
}


@end
